import * as cesium from 'cesium/Cesium'
import * as turf from '@turf/turf'
import { vm, SEND } from '../../../utils/eventManage'
const Cesium = cesium

class RadarManage{
    constructor(mapControl){
        this.mapControl=mapControl;
        this.viewer=mapControl.viewer;
        this.wallList = []
        this.init();
    }
    init(){
        vm.$on(SEND.updateTime, this.updateTime)
    }
    add(item){
        console.log(item)
        this.mapControl.plugins.flowWall.addWall(item.positions);
        this.wallList.push(item);
    }
    updateTime = (time) => {
        let modelEntityList = this.mapControl.modelList;
        let list = [];
        this.wallList.forEach(item => {
            modelEntityList.forEach(mItem => {
                let cartographic = this.mapControl.convert.cartesian3ToDegrees(mItem.position)
                let pt = turf.point([cartographic.longitude, cartographic.latitude]);
                let isHasPoint = turf.booleanPointInPolygon(pt, turf.polygon([item.positions]));
                if(isHasPoint){
                    list.push(mItem);
                }else{

                }
            })
        })
        vm.$emit(SEND.updateWallList, {list:list})
    }
    clear(){
        this.mapControl.plugins.flowWall.removeAllWall();
        this.wallList=[]
    }
}

export default RadarManage;